#include "cGraphics.h"

cGraphics::cGraphics() 
{
	//Create the ID3DXSprite object
	D3DXCreateSprite(g_pD3DDevice, &m_pD3DXSprite);
}

cGraphics::~cGraphics() 
{
	//Release the ID3DXSprite COM object
	SAFE_RELEASE(m_pD3DXSprite);
}

cCamera2D cGraphics::createCamera(D3DXVECTOR3 eyePosition, D3DXVECTOR3 targetPosition, D3DXVECTOR3 upVector) 
{
	//Returns a dynamic camera when called
	return cCamera2D(eyePosition, targetPosition, upVector);
}

void cGraphics::beginSpriteRender(DWORD flags) 
{
	//Call the ID3DXSprite object function for begin rendering
	HR(m_pD3DXSprite->Begin(flags));
}

void cGraphics::flushSprites() 
{
	//Call the ID3DXSprite object function for flush
	//in order to batch sprites together
	HR(m_pD3DXSprite->Flush());
}
void cGraphics::endSpriteRender() 
{
	//Call the ID3DXSprite object function for end rendering
	HR(m_pD3DXSprite->End());
}

void cGraphics::drawSprite(cSprite *sprite) 
{
	//Creates a temporary instance of the texture object
	cTexture *texture = sprite->getTexture();

	//Call the draw function to draw the sprite texture
	HR(m_pD3DXSprite->Draw(texture->m_pTexture, 0, &D3DXVECTOR3(0.0f, 0.0f, 0.0f), 
						0, D3DCOLOR_ARGB(255,255,255,255)));

	//Dynamically Deallocate the temporary object
	texture = NULL;
}

void cGraphics::drawSpriteC(cSprite* sprite, Vector3D center)
{
	cTexture* texture = sprite->getTexture();

	//Call the draw function to draw the sprite texture
	HR(m_pD3DXSprite->Draw(texture->m_pTexture, 0, &D3DXVECTOR3(center.getX(), center.getY(), 0.0f), 
						0, D3DCOLOR_ARGB(255,255,255,255)));

	//Dynamically Deallocate the temporary object
	texture = NULL;
}

void cGraphics::drawAnimation(cAnimation* animation) 
{
	//Start the looping cycle of the animation

	//Draw the frame to the scree
}

void cGraphics::SetTranformation(const D3DXMATRIX &view)
{
	m_pD3DXSprite->SetTransform(&view);
}

void cGraphics::onLostDevice()
{
	m_pD3DXSprite->OnLostDevice();
}

void cGraphics::onResetDevice()
{
	m_pD3DXSprite->OnResetDevice();
}